package com.kaifamiao.month03.day0317;

public class Buy {

    public static void main(String[] args) {
        int[] bills = {4,2,2}; // 账单情况
        int[] prices = {1,2,1}; // 商品的价格
        int[][] combos = {
                {2,1,1,4}
        }; // 套餐
        int result = 0; // 结算金额

        // 使用套餐结算
        int n = (int)(bills[0] / combos[0][0]);
        for(int i = 1; i < bills.length; i ++ ){
            if(n * combos[0][i] > bills[i]){
                break;
            }
            if(i == bills.length - 1){
                result += n * combos[0][combos[0].length - 1];
            }
        }

        // 正常结算的账单
        for(int i = 0; i < bills.length; i ++){
            if(result == 0){
                result += bills[i] * prices[i];
            }else{
                result += (bills[i] - n * combos[0][i]) * prices[i];
            }
        }

        System.out.println(result);
    }
}
